Are the brackets (IF
, and END IF
) properly balanced?
Yes.
|
ask if customer wants coffee IF customer wants coffee THEN charge for coffee ELSE ' decide between tea and milk ask if customer wants tea IF customer wants tea THEN charge customer for tea ELSE charge customer for milk END IF END IF END |
The IF that asks about tea and milk matches the first END IF below it. The IF-THEN-ELSE-END IF is complete by itself, even though it is part of something larger.
ask if customer wants coffee IF customer wants coffee THEN charge for coffee ELSE ' decide between tea and milk ask if customer wants tea IF customer wants tea THEN charge customer for tea ELSE charge customer for milk END IF END IF END
This arrangement of control structures is called nested IFs.
When a computer program needs to make a choice between more than
two branches, nested IF
s are often used.
If there are many choices, there will be many IF
s.
This can get very involved.
Write two QBasic statements for this part of the plan for the program:
ask if customer wants coffee
(Hint: use a character variable called ANSWER$
).